import * as types from "../types/orderListTypes";

const initialState = {
  initing: true,
  loading: false,
  error: undefined,
  orderList: [],
};

export default function orderListReducer(state = initialState, action) {
  switch (action.type) {
    case types.ORDERLIST_LOADING:
      return {
        ...state,
        loading: true,
      };
    case types.ORDERLIST_INIT:
      return {
        ...state,
        initing: true,
      };
    case types.ORDERLIST_DOWN:
      return {
        ...state,
        loading: false,
        initing: false,
        orderList: action.orderList,
      };
    case types.ORDERLIST_ERROR:
      return {
        ...state,
        loading: false,
        initing: false,
        error: action.error,
      };
    case types.ORDERLIST_UNMOUNT:
      return {
        ...initialState,
      };
    default:
      return state;
  }
}
